<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>使用layui</title>
    <link rel="stylesheet" th:href="@{/static/layui/css/layui.css}" type="text/css">
    <link rel="stylesheet" th:href="@{/static/layui/css/formSelects-v4.css}" type="text/css">
</head>
<body>
<br/>
<br/>
<div class="layui-container">
    <form class="layui-form layui-form-pane" action="">
        <div class="layui-form-item">
            <label class="layui-form-label">文章标题</label>
            <div class="layui-input-block">
                <input type="text" name="title" required lay-verify="required" placeholder="请输入标题"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <!--        <div class="layui-form-item">-->
        <!--            <label class="layui-form-label">密码</label>-->
        <!--            <div class="layui-input-block">-->
        <!--                <input type="text" name="password" required lay-verify="required" placeholder="请输入密码" autocomplete="off"-->
        <!--                       class="layui-input">-->
        <!--            </div>-->
        <!--        </div>-->
        <div class="layui-form-item">
            <label class="layui-form-label">文章标签</label>
            <div class="layui-input-block">
                <select name="tags" id="tags" xm-select-skin="normal" lay-search lay-verify="required"
                        lay-filter="tagsSelect" xm-select="tagsXmSelect" xm-select-search>
                </select>
            </div>
        </div>
        <div class="layui-form-item layui-hide">
            <div class="layui-input-block">
                <button id="myBtn" class="layui-btn" type="submit" lay-submit lay-filter="formDemo">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
</body>
<script type="text/javascript" th:src="@{/static/js/jquery-3.4.1.min.js}"></script><!-- 可加自己的jquery -->
<script type="text/javascript" th:src="@{/static/layui/layui.all.js}"></script><!-- 非模块化 -->
<script type="text/javascript" th:src="@{/static/js/formSelects-v4.js}"></script>
<script>
    var formSelects = layui.formSelects;

    //server模式
    formSelects.data('tagsXmSelect', 'server', {
        url: 'http://localhost:8080/tags/tag',
    });
    //监听提交
    layui.form.on('submit(formDemo)', function (data) {
        window.parent.postMessage(JSON.stringify(data.field), '*');
        return false;
    });
</script>
</html>